package com.example.rabbitmqdemo.utils;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Author：DijaH
 * @Date：2023/12/6 15:34
 * @Version：1.0.0
 * @Description：
 *
 * 链接工厂创建信道的工具类
 */
public class RabbitMQUtils {

    public static Channel getChannel() throws IOException, TimeoutException{
        //创建一个链接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //工厂IP，链接rabbitmq队列
        factory.setHost("192.168.32.217");
        factory.setUsername("guest");
        factory.setPassword("guest");

        Connection connection = factory.newConnection();
        //获取信道
        Channel channel = connection.createChannel();
        return channel;
    }

}
